﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithms.Implementation.ComparisonSorts
{
    public class InsertionSort : Algorithm
    {
        protected override void ExecuteAlgorithm(int indexStart, int indexEnd)
        {
            if (indexStart < indexEnd)
            {
                for (int i = (indexStart + 1); i <= indexEnd; i++)
                {
                    int key = _sampleData[i];
                    int j = i - 1;

                    while (j >= indexStart && _sampleData[j] > key)
                    {
                        _sampleData[j + 1] = _sampleData[j];
                        j--;
                    }

                    _sampleData[j + 1] = key;
                }
            }
        }
    }
}
